import { createRouter, createWebHistory } from 'vue-router'
import layout from '@/views/layout'
import login from '@/views/login'
const routes = [
  // 首页
  {
    path: '/',
    component: layout,
    children: [
      {
        path: '', // 二级路由为空 默认显示
        component: () => import('@/views/home')
      },
      {
        path: 'category/:id',
        component: () => import('@/views/category')
      },
      {
        path: 'goods/:id',
        component: () => import('@/views/goods')
      },
      {
        path: 'cart',
        component: () => import('@/views/cart')
      },
      {
        path: 'settlement',
        component: () => import('@/views/settlement')
      },
      {
        name: 'pay',
        path: 'pay/:id',
        component: () => import('@/views/pay')
      }
    ]
  },
  // 登录
  {
    path: '/login',
    component: login

  }
]

// 生成路由实例
const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
